//
//  DEWMessageTableCell.m
//  OtherDemo
//
//  Created by lianjie on 2018/7/24.
//  Copyright © 2018年 lianjie. All rights reserved.
//

#import "DEWMessageTableCell.h"
#import "PPBadgeView.h"

@interface DEWMessageTableCell ()
///头像
@property (nonatomic ,strong) UIView *headerImageV;
///name
@property (nonatomic ,strong) UILabel *nameLab;
///内容
@property (nonatomic ,strong) UILabel *descLab;
///时间
@property (nonatomic ,strong) UILabel *dateLab;
///小红点
@property (nonatomic ,strong) PPBadgeLabel *badgeLab;
@end

@implementation DEWMessageTableCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
     
        [self creatView];
        
    }
    return self;
}

- (void) creatView
{
    ///头像
    _headerImageV = [[UIView alloc]init];
    _headerImageV.backgroundColor = WhiteColor;
    [self.contentView addSubview:_headerImageV];
    ///name
    _nameLab = [self backLabWithColor:UIColorFromRGB(0x333333) size:16.0f];
    
    ///时间
    _dateLab = [self backLabWithColor:UIColorFromRGB(0x999999) size:11.0f];
    _dateLab.textAlignment = NSTextAlignmentRight;
    ///副标题
    _descLab = [self backLabWithColor:UIColorFromRGB(0x999999) size:12.0f];
    ///小红点
    
    _badgeLab = [PPBadgeLabel defaultBadgeLabel];
    _badgeLab.backgroundColor = PointColor;
//    _badgeLab.flexMode = PPBadgeViewFlexModeMiddle;
    
    [self.contentView addSubview:_badgeLab];
    
    [self setupFrame];
    
}


- (void) setupFrame
{
    CGFloat imageWH = 45.0f;///头像宽高
    CGFloat mergin = Margin_15;///边距
    CGFloat dateW = 60.0f;
    //
    _headerImageV.frame = CGRectMake(mergin, mergin, imageWH, imageWH);
//    _headerImageV.layer.cornerRadius = imageWH/2;
//    _headerImageV.layer.masksToBounds = YES;
    //
    _nameLab.frame = CGRectMake(_headerImageV.right+mergin, mergin, DEWScreenWidth-_headerImageV.right-mergin*3-dateW, 23.0f);
    //
    _dateLab.frame = CGRectMake(DEWScreenWidth-mergin-dateW, mergin, dateW, _nameLab.height);
    
    //
    _descLab.frame = CGRectMake(_nameLab.left, _nameLab.bottom+6, _nameLab.width, 17.0f);
    //
    _badgeLab.p_centerX = _dateLab.x+_dateLab.width/2;
    _badgeLab.p_centerY = _descLab.p_centerY;
    
    self.lj_lineWith =DEWScreenWidth-_descLab.left;
//    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(_descLab.left, 69, DEWScreenWidth-_descLab.left, 1.0f)];
//    self.line = line;
//    line.backgroundColor = CellLineColor;
//    [self.contentView addSubview:line];
    
}

///赋值
-(void)setMessageInfo:(NSMutableDictionary *)messageInfo
{
    _headerImageV.backgroundColor = [UIColor grayColor];
//    [_headerImageV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",SERVER_URL,messageInfo[@""]]] placeholderImage:kDefalutUserHeader];
    _headerImageV = [JJHeaders createHeaderView:45.0f images:nil];
    
    _nameLab.text = [NSString stringWithFormat:@"你好%@",messageInfo[@""]];
    
    _descLab.text = [NSString stringWithFormat:@"啦啦啦啦啦%@",messageInfo[@""]];
    
    _dateLab.text = [NSString stringWithFormat:@"刚刚%@",messageInfo[@""]];
    
    _badgeLab.text = [NSString stringWithFormat:@"%@",messageInfo[@""]];
    
}



///创建lab
- (UILabel *)backLabWithColor:(UIColor *)color size:(CGFloat)textSize
{
    
    UILabel *lab = [[UILabel alloc]init];
    lab.textColor = color;
    lab.font = [UIFont systemFontOfSize:textSize];
    [self.contentView addSubview:lab];
    
    return lab;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
